package com.atguigu.c_tcp;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {//服务器

    public static void main(String[] args) throws IOException {
        //创建服务端的对象
        ServerSocket ss = new ServerSocket(10010);

        //根据服务的的对象获取Socket对象 --> 此步骤也是在监听客户端发来的消息
        Socket accept = ss.accept();

        //根据Socket对象获取流对象
        InputStream is = accept.getInputStream();

        byte[] bys = new byte[1024];

        //通讯的输入流对象获取数据 -> 读数据
        int len = is.read(bys); //len : 读到的字节个数

        //解析数据 -> byte[] --> 字符串
        String message = new String(bys, 0, len);

        //获取客户端的ip地址对象
        InetAddress address = accept.getInetAddress();

        System.out.println("发件人 : " + address);
        System.out.println("发件信息 : " + message);

        //关闭服务器
        //ss.close();

    }
}
